<?php
class koudai_productControl extends skymvc{
	public $shop; 
	public function __construct(){
		parent::__construct();	
	}
	
	public function onInit(){
		$this->shop=M("koudai")->selectRow(array("where"=>" siteid=".SITEID));
		if(empty($this->shop)){
			$this->gourl(APPADMIN."?m=koudai");
		}
		define("SHOPID",$this->shop['id']); 
	}
	
	function onDefault(){
		 
		 
		$limit=40;
		$where="  shopid=".SHOPID;
		$url=APPADMIN."?m=koudai_product";
		$start=get('per_page','i');
		$option=array(
			"start"=>$start,
			"limit"=>$limit,
			"order"=>"id DESC",
			"where"=>$where,
		);
		$rscount=true;
		$data=M("koudai_product")->select($option,$rscount);
		if($data){
				foreach($data as $k=>$v){
					$productids[]=$v['productid'];
					$shopids[]=$v['shopid'];
				}
				$products=M('product')->getListByIds($productids);
			 	 
				foreach($data as $k=>$v){
					$v['title']=$products[$v['productid']]['title'];
					 
					$v['imgurl']=$products[$v['productid']]['imgurl'];
					$v['p_price'] =$products[$v['productid']]['price'];
					$data[$k]=$v;
				}
			}
	 
		$pagelist=$this->pagelist($rscount,$limit,$url);
		$this->smarty->assign(
			array(
				"data"=>$data,
				"rscount"=>$rscount,
				"pagelist"=>$pagelist,
				 
			)
		);
		$this->smarty->display("koudai_product/index.html");
	}
	
	 
	
	 public function onChPrice(){
		$id=get('id','i');
		$price=get('price');
		$row=M("koudai_product")->selectRow("id=".$id." AND siteid=".SITEID);
		if(empty($row)) $this->goAll("价格修改失败",1);
		M("koudai_product")->update(array(
			"price"=>$price
		),"id=".$id);
		$this->goAll("价格修改成功");
		 
	 }
	
	 
	 
	
}
?>